package com.xueyi.aixihu.pattern;

import com.xueyi.aixihu.config.SpringContextConfig;
import com.xueyi.aixihu.constant.TwoLevelAuditConstant;
import com.xueyi.aixihu.entity.generatedMapper.DtNewsSortMapper;
import com.xueyi.aixihu.entity.po.AxhFinance;
import com.xueyi.aixihu.entity.po.DtNewsSort;
import com.xueyi.aixihu.exception.SzException;
import lombok.Data;

/**
 * 描述
 * @author 刘梓江
 */
@Data
public class FinanceReportAuditProcessDirector {

    private Integer audiLevel;
    private Integer reportAreaType;
    private AxhFinance report;
    private FinanceReportAuditProcess currentProcess;

    public FinanceReportAuditProcessDirector(AxhFinance report) {
        this.report = report;
        //判断什么类型的报表
        DtNewsSortMapper newSort = SpringContextConfig.getBean(DtNewsSortMapper.class);
        DtNewsSort dtNewsSort = newSort.selectByPrimaryKey(report.getFromToAreaId());
        reportAreaType = dtNewsSort.getPid();
        switch (reportAreaType){
            case 2:audiLevel=1;break;   //镇是一级审核
            case 3:audiLevel=2;break;   //村是二级审核
            case 4:audiLevel=2;break;   //居委会是二级审核
            case 16:audiLevel=2;break;  //社区是二级审核
        }

        //判断报表状态获取状态流程操作对象
        Integer currentReportState=report.getCurrentStatus();
        if(currentReportState.equals(TwoLevelAuditConstant.DRAFT)||currentReportState.equals(TwoLevelAuditConstant.ONE_FAIL)){

            //设置提交流程对象
            currentProcess=FinanceReportSubmitProcess.getInstance();

        }else if(currentReportState.equals(TwoLevelAuditConstant.SUBMIT_AUDIT)||currentReportState.equals(TwoLevelAuditConstant.TWO_FAIL)){

            //设置一级审核流程对象
            currentProcess=FinanceReportOneLevelAuditProcess.getInstance();

        }else if(currentReportState.equals(TwoLevelAuditConstant.ONE_CONSENT)&&audiLevel>=2){

            //设置二级审核流程对象
            currentProcess=FinanceReportTwoLevelAuditProcess.getInstance();

        }else{

            //设置发布流程对象
            currentProcess=FinanceReportReleaseProcess.getInstance();
        }
    }

    //提交
    public void submit() throws SzException {
        currentProcess.submit(this);
    }

    //同意
    public void passed() throws SzException {
        currentProcess.passed(this);
    }

    //拒绝
    public void dismiss(String dismissDesc) throws SzException {
        currentProcess.dismiss(dismissDesc,this);
    }

    //拒绝
    public void release() throws SzException {
        currentProcess.release(this);
    }

}
